package cn.rokhdelar.umbrsapi.test;

import cn.rokhdelar.umbrsapi.config.annotation.CurrentUser;
import cn.rokhdelar.umbrsapi.core.controller.BaseController;
import cn.rokhdelar.umbrsapi.core.dto.PageResult;
import cn.rokhdelar.umbrsapi.core.entity.BasePageDto;
import cn.rokhdelar.umbrsapi.core.jpa.CriteriaConstant;
import cn.rokhdelar.umbrsapi.core.jpa.FilterMap;
import cn.rokhdelar.umbrsapi.core.jpa.nativesql.QueryHelper;
import cn.rokhdelar.umbrsapi.core.utils.Result;
import cn.rokhdelar.umbrsapi.management.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: umbrs-api-tool
 * @BelongsPackage: cn.rokhdelar.umbrsapi.test
 * @Author: shenyongqiang
 * @CreateTime: 2024-06-12  10:24
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("/SmUrlController")
public class StudentController extends BaseController<Student> {
    @Override
    protected Class<Student> getEntityClass() {
        return Student.class;
    }

    @Autowired
    private StudentService studentService;

    @RequestMapping(path = "/save", method = RequestMethod.POST)
    @ResponseBody
    public Result save(@RequestBody Student info) {
        Student student = getBaseService().doSave(info);
        return super.success(student);
    }

    @RequestMapping(value = "/pageTokenList", method = RequestMethod.POST)
    @ResponseBody
    public PageResult pageversionList(@RequestBody BasePageDto dto, @CurrentUser SysUser user) {
        FilterMap filterMap = new FilterMap();
        Sort.Order orderDt = new Sort.Order(Sort.Direction.DESC, "createdDateTime");
        filterMap.likeVal("address","add");
        Map<String,Object> map  = new HashMap();
//        map.put(CriteriaConstant.LO,LocalDateTime.parse("2024-06-12 22:29:26",  DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
//        map.put(CriteriaConstant.HI, LocalDateTime.now());
//        filterMap.between("createdDateTime", map);
        map.put(CriteriaConstant.LO,2);
        map.put(CriteriaConstant.HI, 3);
        filterMap.between("id", map);

        FilterMap filter = new FilterMap();
        filter.eq("leader", "leader1");
        filter.eq("responsibility", "responsibility2");
        filterMap.or("name", filter);
        PageResult byPage = getBaseService().findByPage(filterMap, Student.class, Sort.by(orderDt), dto.getCurrent() - 1, dto.getPageSize());
        return byPage;
    }

    @RequestMapping(value = "/pageTokenListHelper", method = RequestMethod.POST)
    @ResponseBody
    public PageResult pageTokenListHelper(@RequestBody BasePageDto dto) {
        PageResult byPage = studentService.pageHelper(dto);
        return byPage;
    }

    @RequestMapping(value = "/dosave", method = RequestMethod.POST)
    @ResponseBody
    public void dosave(@RequestBody Student dto) {
        studentService.savestudent(dto);
    }

    @RequestMapping(value = "/ListSqlHelper", method = RequestMethod.POST)
    @ResponseBody
    public List<Map<String, Object>> ListSqlHelper(@RequestBody BasePageDto dto) {
        List<Map<String, Object>> maps = studentService.ListSqlHelper(dto);
        return maps;
    }


}
